package cn.edu.scau.cmi.yangzhichao.composite.safe;

import cn.edu.scau.cmi.yangzhichao.client.SafeCompositeClient;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

import java.util.List;


public class SafeCompositeViewController {
    private static SafeComposite root;
    private static String showText="";
    @FXML
    private TextArea textArea;
    @FXML
    private void initialize(){
        root=new SafeComposite("root");
        root.addChild(new SafeLeaf("LeafA"));
        SafeComposite composite=new SafeComposite("BranchA");
        composite.addChild(new SafeLeaf("LeafB"));
        SafeComposite composite1=new SafeComposite("BranchB");
        composite1.addChild(new SafeLeaf("LeafC"));
        composite.addChild(composite1);
        root.addChild(composite);
    }
    @FXML
    private void handleShow(){
        textArea.setText("");
        showText="";
        root.display(0);
        textArea.setText(showText);
    }
    @FXML
    private void handleAdd(){
        root.addChild(new SafeComposite("Branch"));
        root.addChild(new SafeLeaf("Leaf"));
        handleShow();
    }
    @FXML
    private void handleDelete(){
        root.deleteChild(root.getChildren().size()-1);
        handleShow();
    }
    @FXML
    private void handleUpdate(){
        root.updateChild(new SafeLeaf("updateLeaf"),root.getChildren().size()-1);
        handleShow();
    }
    public static void addToTextView(String string){
         showText+=string;
    }

}
